import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STITIC_DIR = os.path.join(BASE_DIR, 'static')


def make_conn(info):
    host = info.get('host')
    port = info.get('port')
    user = info.get('user')
    password = info.get('password')
    db = info.get('db')
    return "mysql+pymysql://%s:%s@%s:%s/%s" % (user, password, host, port, db)


class Config(object):
    DEBUG = False
    TESTING = False
    SECRET_KEY = "USER_API"

    @staticmethod
    def init_app(app):
        pass


class DevlopmentConfig(Config):
    ENV = 'development'
    DEBUG = True
    SERVER_NAME = 'localhost:8001'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    DB_CONFIG = {
        'host': '127.0.0.1', 'port': 3306, 'user': 'root',
        'password': '0118', 'db': 'wyy', 'connect_timeout': 300,
        'read_timeout': 300, 'write_timeout': 300,
        'charset': 'utf8'
    }
    SQLALCHEMY_DATABASE_URI = make_conn(DB_CONFIG)


class TestingConfig(Config):
    DEBUG = False
    SERVER_NAME = 'localhost:8001'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    DB_CONFIG = {
        'host': '127.0.0.1', 'port': 3306, 'user': 'root',
        'password': '0118', 'db': 'wyy', 'connect_timeout': 300,
        'read_timeout': 300, 'write_timeout': 300,
        'charset': 'utf8'
    }
    SQLALCHEMY_DATABASE_URI = make_conn(DB_CONFIG)


class ProductionConfig(Config):
    DEBUG = False
    SERVER_NAME = 'localhost:8001'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    DB_CONFIG = {
        'host': '127.0.0.1', 'port': 3306, 'user': 'root',
        'password': '0118', 'db': 'wyy', 'connect_timeout': 300,
        'read_timeout': 300, 'write_timeout': 300,
        'charset': 'utf8'
    }
    SQLALCHEMY_DATABASE_URI = make_conn(DB_CONFIG)


env = {
    'development': DevlopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevlopmentConfig
}
